
/**
 * @Title: BaseImgView.java
 * @Package: com.pingan.papd.ui.activities.discover
 * @Description: TODO
 * @author xiezhidong@pajk.cn  
 * @date 2014-8-27 下午2:16:52 
 */


package com.harwkin.nb.camera;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.widget.ImageView;

import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions.Builder;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.utils.ImageLoaderUtil;

import cn.afactory.tygz.ui.base.utils.ImageUtils;

public class BaseImgView {

    private static final String TAG = BaseImgView.class.getSimpleName();


    /**
     * @param imgView        图片
     * @param path           URL
     * @param defaultbg      默认图片，不需要 -1
     * @param loadbg         默认图片，不需要 -1
     * @param failbg         默认图片，不需要 -1
     * @param imageScaleType
     * @param width          px
     * @param height         px
     * @param RadiusPixels   圆形图片直径 ,不需要-1 , 0为自动适配  px
     * @Description 加载显示图片
     * @author xiezhidong@pajk.cn
     */

    public static void loadimg(ImageView imgView, String path, int defaultbg, int loadbg, int failbg,
                               ImageScaleType imageScaleType, int width, int height, int RadiusPixels) {
        if (imgView == null || path == null) {
            return;
        }

        ImageLoader imageLoader = ImageLoader.getInstance();
        Builder builder = new DisplayImageOptions.Builder();
        builder.showImageOnLoading(loadbg > 0 ? loadbg : ImageLoaderUtil.getImageDefaultBG())
                .showImageForEmptyUri(defaultbg > 0 ? defaultbg : ImageLoaderUtil.getImageEmpty())
                .showImageOnFail(failbg > 0 ? failbg : ImageLoaderUtil.getImageErrorBG()).cacheInMemory(true)
                .cacheOnDisk(true).considerExifParams(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565);
        if (RadiusPixels > 0) {
            builder.displayer(new RoundedBitmapDisplayer(RadiusPixels));
        } else if (RadiusPixels != 0) {
            if (width > 0 && height > 0)
                if (width > height) {
                    builder.displayer(new RoundedBitmapDisplayer(height));
                } else {
                    builder.displayer(new RoundedBitmapDisplayer(width));
                }
        }
        LogUtils.i("loadimg:" + path + ". Width:" + width + ",Height:" + height);
        DisplayImageOptions options = builder.build();


        if (path != null) {// 加载网络图片
            String sizeStr = "";
            if (imageScaleType == null) {

                if (width > 0 && height > 0) {
                    sizeStr = width + "x" + height;
                }
                imageLoader.displayImage(ImageUtils.getThumbnailFullPath(path, sizeStr), imgView, options);
            } else {
                imageLoader.displayImage(ImageUtils.getImageFullUrl(path), imgView, options);
            }
            // imImgView.loadImage();
        }
//		else {// 加载本地图片
//			imageLoader.displayImage(Scheme.FILE.wrap(path), imgView, options);
//		}
    }

    /**
     * 判断图片地址是否是网络地址
     *
     * @param audioPath
     * @return
     */
    public static boolean isTfsPath(String audioPath) {
        return !TextUtils.isEmpty(audioPath)
                && audioPath.toLowerCase().startsWith("tfs://");
    }
}
